public class MyQueue {


    static class Node {
        public int val;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }

        public Node front;
        public Node rear;

        public void offer(int val) {
            Node node = new Node(val);
            if (front == null) {
                front = node;
                rear = node;
            } else {
                rear.next = node;
                rear = rear.next;
            }
        }

        public int poll() {
            if (front == null) {
                return -1;
            }
            int oldVal = front.val;
            if (front.next != null) {
                front = front.next;

            } else {
                front = null;
                rear = null;
            }
            return oldVal;
        }
        public int peek(){
             if (front == null){
                 return -1;
             }
             return front.val;
        }
}


